package com.baizhou.honglv.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 * @author HaiPeng Wang
 * @date 2021/7/17 18:05
 * @Description:
 */
@Configuration
public class FileUploadConfig {
    @Bean(name = "multipartResolver")   //放到容器中必须是这个名字
    public MultipartResolver setMultipartResolver(){
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");  //设置解析文件的编码格式
        resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析，以在在UploadAction中捕获文件大小异常
        resolver.setMaxInMemorySize(40960);  //设置内存中保存文件的最大大小，超过这个大小会写入到磁盘当中
        resolver.setMaxUploadSize(5*1024*1024);//上传文件大小 5M 5*1024*1024  单位是字节
        return resolver;
    }
}
